<template>
  <div id="trainingInformationData">
    <div v-if="rowData1 == '竞赛资讯'">
      <header>
        {{ rowData.raceName || '暂无数据' }}
      </header>
      <!--line-->
      <div class="line">
        <div class="left">{{ rowData.deptName || '暂无数据' }}</div>
        <div class="right">{{ rowData.createDate || '暂无数据' }}</div>
      </div>
      <div class="List" style="clear: both">
        <div class="ListT" v-for="(item, index) in ListData1" :key="index"
          style="display: flex;justify-content: center;align-items: center;color: black;border-bottom: 1px solid #d2d2d2;">
          <van-field v-if="item.name !== '培训地点'" readonly clickable v-model="rowData[item.prop]" :label="item.name">
          </van-field>
          <van-field v-else readonly clickable v-model="rowData4" :label="item.name">
          </van-field>
        </div>
        <header style="margin-top: 10px">竞赛内容</header>
        <div class="pxnr">
          <van-field v-model="rowData.raceComment" rows="3" autosize type="textarea" />
        </div>
      </div>
      <div class="TZWJ">
        <div class="left">
          <ul v-for="(item, index) in fileId" :key="index">
            <li>通知文件:<a @click="handletopdf(item)" style="color: aqua">通知文件.PDF</a></li>
          </ul>
        </div>
        <!-- <div class="right">{{ rowData.raceName || '暂无数据' }}</div> -->
      </div>
    </div>
    <div v-else>
      <header>
        {{ rowData.trainTitle || '暂无数据' }}
      </header>
      <!--line-->
      <div class="line">
        <div class="left">{{ rowData.issueDepartment || '暂无数据' }}</div>
        <div class="right">{{ rowData.createTime || '暂无数据' }}</div>
      </div>
      <div class="List" style="clear: both">
        <div
          class="ListT"
          v-for="(item, index) in ListData"
          :key="index"
          style="
            display: flex;
            justify-content: center;
            align-items: center;
            color: black;
            border-bottom: 1px solid #d2d2d2;
          "
        >
          <van-field readonly clickable v-if="item.prop=='trainTime'"  v-model="CStime"  label="培训时间" />
          <van-field readonly clickable v-else-if="item.prop=='belongTown'"  v-model="belongTownArry"  label="参加培训工匠范围" />
          <van-field readonly clickable v-else v-model="rowData[item.prop]" :label="item.name" />
        </div>
        <header style="margin-top: 10px">培训内容</header>
        <div class="pxnr">
          <van-field v-model="rowData.trainContent" rows="3" autosize type="textarea" />
        </div>
      </div>
      <div class="TZWJ">
        <div class="left">
          <ul v-for="(item, index) in fileId" :key="index">
            <li>通知文件:<a @click="handletopdf(item)" style="color: aqua">通知文件.PDF</a></li>
          </ul>
        </div>
        <!-- <div class="right">{{ rowData.issueDepartment || '暂无数据' }}</div> -->
      </div>
    </div>
    <footer>
      <van-button @click="getGJInformcion" type="info" style="width: 90vw"> 我要报名 </van-button>
    </footer>
  </div>
</template>

<style scoped lang="scss">
#trainingInformationData {
  width: 100vw;
  height: 100vh;
  background-color: #fff;
  padding: 12px;
  overflow: hidden;

  header {
    font-size: 18px;
    color: black;
    font-weight: 600;
  }

  footer {
    position: fixed;
    bottom: 34px;
    left: 50%;
    transform: translateX(-50%);
  }

  .pxnr {
    margin-top: 10px;
  }

  .line {
    margin: 6px 0;

    .left {
      float: left;
      color: aquamarine;
    }

    .right {
      float: right;
    }
  }

  .TZWJ {
    margin-top: 10px;

    .left {
      float: left;
    }

    .right {
      margin-top: 20px;
      float: right;
    }
  }
}
</style>

<style>
#trainingInformationData .van-field__label {
  color: black;
  font-weight: 500;
  width: 8em !important;
}

#trainingInformationData .List .pxnr .van-cell {
  border: 1px solid rgb(210, 210, 210);
}

#trainingInformationData .ListT .van-field__control {
  text-align: right;
}
</style>


<script>
import {
  zhejiangHouseTrainingEduByid,
  selectListByIds,
  zhejiangHouseArtisan,
  zhejiangHouseTrainingEduByRE,
  zhejiangHouseTrainingEduByREJS,
} from '@/utils/api'
export default {
  data() {
    return {
      title: '乡村建筑培训通知',
      rowData: {},
      CStime:"",
      belongTownArry:"",
      valuefw:"",
      ListData: [
        {
          name: '培训类型',
          prop: 'trainType',
        },
        {
          name: '培训开始时间',
          prop: 'trainTime',
        },
        {
          name: '培训结束时间',
          prop: 'trainTimeEnd',
        },
        {
          name: '培训地点',
          prop: 'trainAddress',
        },
        {
          name: '学时',
          prop: 'classHour',
        },
        {
          name: '培训机构',
          prop: 'trainAgency',
        },
        {
          name: '参加培训工匠范围',
          prop: 'belongTown',
        },
        {
          name: '报名开始时间',
          prop: 'startTime',
        },
        {
          name: '报名截止时间',
          prop: 'endTime',
        },
      ],
      ListData1: [
        {
          name: '参赛时间',
          prop: 'raceDate',
        },
        {
          name: '参赛地点',
          prop: 'racePlace',
        },
        {
          name: '参加竞赛工匠范围',
          prop: 'raceArtisanRangeCh',
        },
        {
          name: '报名开始时间',
          prop: 'startDate',
        },
        {
          name: '报名截止时间',
          prop: 'endDate',
        },
      ],
      JFData: {
        APPLYPHONE: '',
      },
      baseUrl: window.g.OSSPriview1,
      file: '',
      ids: '',
      rowDataID: '',
      isread: false,
      ENUM: {},
      onConfirm5: [],
      sexName: '',
      rowData1: '',
      fileId: [],
    }
  },
  computed: {
  },
  async mounted() {
    this.rowDataID = this.$route.query.data
    this.rowData1 = this.$route.query.rowData
    if (ZWJSBridge) {
      this.isreadonsly1 = true
      ZWJSBridge.setTitle({
        title: this.rowData1 == '竞赛资讯' ? '竞赛资讯' : '培训资讯',
      })
        .then((res) => { })
        .catch((err) => {
          this.isreadonsly1 = false
        })
    }
    if (this.rowData1 == '竞赛资讯') {
      this.rowData = JSON.parse(this.$route.query.data1)
      const res1 = await selectListByIds(this.rowData.fileId)
      if (res1.data.code == 500) {
        this.$toast.fail(res.data.msg)
      } else {
        res1.data.data.forEach(element => {
          this.fileId.push(element.fileId)
        });
      }
    } else {
      this.getData(this.rowDataID)
    }
  },
  methods: {
    //获取工匠信息
    async getGJInformcion() {
      let data = {
        accessCode: 'd6158bcf5e1c4a079375143b67b311f3',
        cityCode: '441300000000',
        id: window.localStorage.getItem('DanDianid') || '',
      }
      const res = await zhejiangHouseArtisan(data)
      if (!res.data.data) {
        // this.$toast.fail('系统未查询到您的工匠信息，请联系区县建设部门录入!')
        this.ids = '1'
        if (this.rowData1 !== '竞赛资讯') {
          let params = this.rowData
          params.idCard = window.localStorage.getItem('DanDianid')
          const res = await zhejiangHouseTrainingEduByRE(params)
          if (res.data.code == 200) {
            // this.$toast.success('报名成功')
            this.handleGoto(res.data.data.trainEduId)
          } else {
            this.$toast.fail(res.data.msg)
          }
        } else {
          let params = this.rowData
          params.idCard = window.localStorage.getItem('DanDianid')
          const res = await zhejiangHouseTrainingEduByREJS(params)
          if (res.data.code == 200) {
            // this.$toast.success('报名成功')
            this.handleGoto(res.data.data.racePublicId)
          } else {
            this.$toast.fail(res.data.msg)
          }
          // this.handleGoto(this.rowData.id)
        }
      } else {
        this.ids = '0'
        if (this.rowData1 !== '竞赛资讯') {
          let params = this.rowData
          params.idCard = window.localStorage.getItem('DanDianid')
          const res = await zhejiangHouseTrainingEduByRE(params)
          if (res.data.code == 200) {
            // this.$toast.success('报名成功')
            this.handleGoto(res.data.data.trainEduId)
          } else {
            this.$toast.fail(res.data.msg)
          }
        } else {
          let params = this.rowData
          params.idCard = window.localStorage.getItem('DanDianid')
          const res = await zhejiangHouseTrainingEduByREJS(params)
          if (res.data.code == 200) {
            // this.$toast.success('报名成功')
            this.handleGoto(res.data.data.racePublicId)
          } else {
            this.$toast.fail(res.data.msg)
          }
          // this.handleGoto(this.rowData.id)
        }
      }
    },
    async handletopdf(data) {
      if (!data) {
        this.$toast.fail('暂无数据')
        return
      }
      let url = window.g.BaseURL + 'api/upload/oss/preview?fileId=' + data
      // this.$router.push({
      //   path: '/PDFJSViewer',
      //   query: {
      //     path: url,
      //   },
      // })
      if (window.sessionStorage.getItem('showBg1') == 'true') {
        this.$router.push({
          path: '/PDFJSViewer',
          query: {
            path: url,
          },
        })
      } else {
        //根据id获取
        let url1 = ''
        const res = await selectListByIds(data)
        url1 = this.baseUrl + res.data.data[0].path
        //iphone先这样处理
        if (ZWJSBridge) {
          ZWJSBridge.openLink({
            url: url1,
          })
            .then((res) => { })
            .catch((err) => {
              window.open(url1)
            })
        }
      }
    },
    handleGoto(data) {
      //先判断当前身份证号是否存在
      this.$router.push({
        path: '/Registration',
        query: {
          data: data,
          id: this.ids, //0是存在工匠信息  1是不存在需要新增
          data1: this.rowData1,
          //培训教育 需要传入trainType判断是否为初次教育
          trainType: this.rowData.trainType
        },
      })
    },
    async getData(id) {
      const res = await zhejiangHouseTrainingEduByid(id)
      debugger
      this.rowData = res.data.data
      this.rowData.address.forEach(item => {
        this.rowData4 = this.rowData4 + item.belongTown + '、'
      })
      console.log(this.rowData4,'1111111111111')
      this.rowData.trainType = res.data.data.trainType
      this.valuefw=this.rowData.belongCity
      if(this.rowData.trainTime ||this.rowData.trainTimeEnd){
        this.CStime=this.rowData.trainTime +"至"+this.rowData.trainTimeEnd
      }
     if(this.rowData.address&&this.rowData.address.length>0){
       var  newCity=[];
      this.rowData.address.forEach((iteme)=>{
        newCity.push(iteme.belongVillage);
      })
      this.belongTownArry=newCity.toString();
     }
      debugger
      // this.fileId = this.rowData.fileId.split(',')
      //先调用selectListByIds
      const res1 = await selectListByIds(this.rowData.fileId)
      if (res1.data.code == 500) {
        this.$toast.fail(res.data.msg)
      } else {
        res1.data.data.forEach(element => {
          this.fileId.push(element.fileId)
        });
      }
      console.log(this.fileId)
    },
  },
}
</script>
v
